limsEquiptRepair.editPage = {

    getGridParam: function () {
        var _this = this;
        return {
            type: 'grid',
            id: 'equiptRepairGrid-edit',
            url: limsEquiptRepair.baseUrl + '/queries/raw',
            service: 'limsEquiptRepairServiceImpl',
            dbTable: 'T_LIMS_EQUIPT_REPAIR',
            columns: limsEquiptRepair.getEditListColumns(),
            requestData: {
                createdById_SEQ: workspace.user.id
            },
            deleteFormatter: function (row) {
                return Gikam.isNotEmpty(row.ext$.equiptcode) ? row.ext$.equiptcode : row.id;
            },
            onCellClick: function (field, row) {
                field === 'ext$.equiptcode' && _this.loadDetailPage(row.id);
            },
            onBeforeUpdate : function(rows) {
                var currentTime = new Date(Date.now());
                var expectDate = new Date(rows.expectDate);
                if (expectDate < currentTime) {
                    Gikam.alert("请选择当前日期以后的日期");
                    return false;
                }
            },
            toolbar: [{
                type: 'button',
                text: 'GIKAM.BUTTON.INSERT',
                icon: 'add',
                onClick: function () {
                    Gikam.create('modal', {
                        title: Gikam.choose.getConfig('equiptChoose').title,
                        url: Gikam.choose.getConfig('equiptChoose').url + Gikam.param({
                            single: true,
                            equiptStatus_SEQ: 'Damage',
                        }),
                        width: '90%',
                        height: '90%',
                        onAfterClose: function (rows) {
                            if (Gikam.isNotEmpty(rows)) {
                                var row = rows[0]
                                Gikam.preInsert({
                                    modalTitle: 'BASEMODULE.TRM.EQUIPT.REPAIRS.MODAL.ADD',
                                    fields: limsEquiptRepair.getBaseInfoFormFields(),
                                    url: limsEquiptRepair.baseUrl,
                                    param: {
                                        equiptId: row.id
                                    }
                                }).done(function (id) {
                                    Gikam.getComp('equiptRepairGrid-edit').refresh();
                                });
                            }
                        }
                    })
                }
            }, {
                type: 'button',
                text: 'GIKAM.BUTTON.DELETE',
                icon: 'remove-row',
                onClick: function () {
                    Gikam.getComp('equiptRepairGrid-edit').deleteRows(limsEquiptRepair.baseUrl);
                }
            }, {
                type: 'button',
                text: 'GIKAM.WORKFLOW.BUTTON.SUBMIT',
                icon: 'submit', color: 'success',
                onClick: function () {
                    var comp = Gikam.getComp('equiptRepairGrid-edit');
                    if (!(comp.getSelections().length > 0) || !comp.validate(comp.getSelections())) {
                        return;
                    }
                    _this.submit();
                }
            }]
        }
    },

    submit: function () {
        var grid = Gikam.getComp('equiptRepairGrid-edit');
        Gikam.create('workflow').submit({
            data: grid.getSelections(),
            pageObject: limsEquiptRepair
        }).done(function () {
            grid.refresh();
        });
    },

    loadDetailPage: function (id) {
        workspace.window.load(limsEquiptRepair.baseUrl + '/page/detail' + Gikam.param({
            id: id,
            page: 'edit',
        }));
    },

    create: function () {
        var _this = this;
        Gikam.create('layout', {
            id: 'lims-equipt-repair-edit-list-layout',
            renderTo: workspace.window.$dom,
            center: {
                items: [this.getGridParam()]
            }
        });
    },

    init: function () {
        this.create();
    }
};
